<template>
	<view class="page" v-if="loading">
		<template v-if="type === 'goods'&&step==1">
			<ItemGoods :isOrder="true" :item="release_detail" :type="2">
				<template v-slot:btns>
					<view class="order_body_details">
						<view>
							<view class="button" @click="goDetail">
								{{ ($t('查看详情')) }}
							</view>
						</view>
					</view>
				</template>
			</ItemGoods>
		</template>

		<template v-if="type === 'transport'&&step==1">
			<ItemTransportList :isOrder="true" :item="release_detail" :type="2">
				<template v-slot:btns>
					<view class="order_body_details" style="margin-top: 30rpx;">
						<view>
							<!-- <view class="button" @click="goDetail">
								{{ ($t('查看详情')) }}
							</view> -->
						</view>
					</view>
				</template>
			</ItemTransportList>
		</template>

		<template v-if="type === 'crossborder'&&step==1">
			<ItemFreightForwarder :isOrder="true" :item="release_detail" :orderDetail="{}" :type="2">
				<template v-slot:btns>
					<view class="order_body_details">
						<view>
							<view class="button" @click="goDetail">
								{{ ($t('查看详情')) }}
							</view>
						</view>
					</view>
				</template>
			</ItemFreightForwarder>
		</template>

		<template v-if="type === 'professional'&&step==1">
			<ItemAgencyList :isOrder="true" :item="release_detail" :type="2" @communicates="communicates"
				@communicate="communicate" :im="1">
				<template v-slot:btns>
					<view class="order_body_details">
						<view>
							<!-- <view class="button" @click="goDetail">
								{{ ($t('查看详情')) }}
							</view> -->
						</view>
					</view>
				</template>
			</ItemAgencyList>
		</template>

		<!-- <my-title title="基本信息" v-if="false"></my-title>
		<user-info :info="release_detail.userInfo" v-if="false"></user-info>
		<view class="my-detail" v-if="false">
			<view>{{ $t(releaseType) }}</view>
			<view style="color: #f79829;" @click="goDetail">{{ $t('查看详情') }}></view>
		</view> -->

		<block v-if="type === 'crossborder'&&step==1">
			<view class="server">
				<my-title :title="$t('所需服务')" :padding_="1" cusStyle="background: #fefcf6;"></my-title>
				<view class="flex">
					<u-image v-if=" baoguan == 1 " :src="HTTP_IMG_UTL+'crossborder2.png'" height="200rpx"
						mode="heightFix"></u-image>
					<u-image v-if=" qingguan ==1 " :src="HTTP_IMG_UTL+'crossborder1.png'" height="200rpx"
						mode="heightFix"></u-image>
				</view>
				<view class="flex">
					<img v-if="details.is_express_price == 2" :src="HTTP_IMG_UTL+'crossborder3.png'" />
					<img v-if="details.is_warehouse == 2" :src="HTTP_IMG_UTL+'crossborder4.png'" />
					<img v-if="details.is_load_unload == 2" :src="HTTP_IMG_UTL+'crossborder5.png'" />
				</view>
			</view>
		</block>


		<block v-if="type === 'goods'&&step==1">
			<view class="my-content-bottom">
				<my-title title="需求信息" :padding_="1" cusStyle="background: #fefcf6;"></my-title>
				<view style="padding: 0 10px;display: flex;	background: #fefcf6;width: 100%;">
					<view style="width: 50%">{{ $t('参与类型') }}</view>
					<view style="width: 50%;text-align: right;">{{ getShowMsg() }}</view>
				</view>

				<view class="goods_now">
					<view style="width: 55%">{{ $t('期望单价') }}</view>
					<view style="width: 45%;text-align: right;">
						{{ release_detail[$t('desire_price')]}}
						{{$t(release_detail.price_unit)}}/{{ release_detail[$t('item.number_unit')]}}
					</view>
				</view>
				<view class="goods_now">
					<view style="width: 50%">{{ $t('需求数量') }}</view>
					<view style="width: 50%;text-align: right;">
						{{ release_detail[$t('goods_num')]}}
						{{ release_detail[$t('item.number_unit')]}}
					</view>
				</view>
				<view class="goods_now"
					style="line-height: 60rpx; width:100%;padding-bottom: 20rpx;height: auto;display: inline-block;">
					<view style="width: 50%">{{ $t('采购清单') }}</view>
					<view v-if="release_detail.filelist&&release_detail.filelist.length!=0" class="detailData_content"
						@click="downLoadFile(release_detail.filelist)"
						style="margin-left: auto;padding-left: 15rpx;padding-right: 15rpx;">
						{{ release_detail.filelist.substring(release_detail.filelist.length, release_detail.filelist.length - 20) }}
					</view>
				</view>
			</view>
		</block>

		<!-- {{form}}
		<br>
		{{form2}}
		<br>
		{{form3}} -->
		<!-- {{selectedVehicleItem}} -->



		<!-- 运输工具选择 -->
		<view v-if="type=='transport'&&release_detail.release_type==2">
			<div class="title">
				{{$t("请选择")}}
			</div>

			<div @click="selectVehicleShow=true">
				<vehicleItem :item="selectedVehicleItem" />
			</div>

			<u-popup v-model="selectVehicleShow" mode="bottom" border-radius="40" width="40">
				<selectVehicle :selectVehicleShow.sync="selectVehicleShow" @checkItemSubmit="checkItemSubmit">
				</selectVehicle>
			</u-popup>
		</view>
		<!-- 运输工具选择 -->


		<view class="my-content-bottom"
			v-if="(release_detail.release_type==2&&selectedVehicleItem.id||release_detail.release_type!=2)">
			<my-title title="竞标信息" :padding_="1" cusStyle="background: #fefcf6;"></my-title>

			<block v-if="step_count==1">

				<buildForm :bg="'2'" v-if="formLoading" :formItems="formItems" :value="form" @input="formInput"
					:select_city_new="[]" :select_city_newd="[]" />
				<br>
				<view style="padding-bottom: 34.88rpx">
					<u-button :custom-style="{
				        width: '656rpx',
				        height: '63rpx',
						marginTop:'40rpx',
				        background: 'linear-gradient(110deg, #DD2910 0%, #F79B29 100%)',
				        borderRadius: '26rpx'
				    }" hover-class="none" type="primary" @click="subForm">
						{{ $t(jb) }}
					</u-button>
					<view style="width: 100%;height: 100rpx;"></view>
				</view>
			</block>

			<block v-if="step_count==2">

				<!-- 				<swiper :current="step-1" :style="{height:form_height+'px'}"  @change="swiperChange"> -->

				<!-- <swiper-item class="swiper-item"  @touchstart="itemTouchStart" @touchend="itemTouchEnd">
						<scroll-view scroll-y style="background-color: #f6f6f6;" :style="{height:form_height+'px'}">	 -->

				<block v-if="step==1">
					<view style="width: 100%;margin-left: 0%;overflow-y: auto;" :style="{height:form_height+'px'}">
						<buildForm :bg="'2'" v-if="formLoading" :formItems="formItems" :value="form" @input="formInput"
							:select_city_new="[]" :select_city_newd="[]" />
						<br>
						<u-button :custom-style="customStyle" hover-class="none" :disabled="subDisabled" type="primary"
							@click="nextStep">{{ $t('下一步') }}
						</u-button>
						<view style="width: 100%;height: 100rpx;"></view>
					</view>
				</block>


				<!-- </scroll-view>
					</swiper-item> -->

				<!-- <swiper-item class="swiper-item"  @touchstart="itemTouchStart" @touchend="itemTouchEnd">
						<scroll-view scroll-y style="background-color: #f6f6f6;" :style="{height:form_height+'px'}">		 -->
				<block v-if="step==2">
					<view style="width: 100%;margin-left: 0%;overflow-y: auto;" :style="{height:form_height+'px'}">
						<buildForm :bg="'2'" v-if="formItems2" :formItems="formItems2" :value="form2"
							@input="formInput2" :select_city_new="[]" :select_city_newd="[]" />
						<br>
						<view style="width: 100%;display: flex;margin-top: 50rpx;">
							<view class="my-step custom_" @click="prevStep">{{ $t('上一步') }}</view>
							<view style="padding-bottom: 34.88rpx">
								<u-button :custom-style="{
											width: '356rpx',
											height: '83rpx',
											background: 'linear-gradient(110deg, #DD2910 0%, #F79B29 100%)',
											borderRadius: '56rpx'
										}" hover-class="none" type="primary" @click="subForm">
									{{ $t(jb) }}
								</u-button>
								<view style="width: 100%;height: 100rpx;"></view>

							</view>
						</view>
					</view>
				</block>

				<!-- </scroll-view>
					</swiper-item>
				</swiper> -->

			</block>


			<block v-if="step_count==3">

				<!-- <swiper :current="step-1" :style="{height:form_height+'px'}" @change="swiperChange">
					<swiper-item class="swiper-item"  @touchstart="itemTouchStart" @touchend="itemTouchEnd">
						<scroll-view  scroll-y style="background-color: #f6f6f6;" :style="{height:form_height+'px'}">		 -->
				<block v-if="step==1">
					<view style="width: 100%;margin-left: 0%;overflow-y: auto;" :style="{height:form_height+'px'}">
						<buildForm :bg="'2'" :radius_="'2'" v-if="formLoading" :formItems="formItems" :value="form"
							@input="formInput" :select_city_new="[]" :select_city_newd="[]" />
						<br>
						<u-button :custom-style="customStyle" hover-class="none" :disabled="subDisabled" type="primary"
							@click="nextStep">{{ $t('下一步') }}
						</u-button>
						<view style="width: 100%;height: 100rpx;"></view>
					</view>
				</block>

				<!-- </scroll-view>
					</swiper-item> -->

				<!-- <swiper-item class="swiper-item"  @touchstart="itemTouchStart" @touchend="itemTouchEnd">
						<scroll-view  scroll-y style="background-color: #f6f6f6;" :style="{height:form_height+'px'}">	 -->
				<block v-if="step==2">
					<view style="width: 100%;margin-left: 0%;overflow-y: auto;" :style="{height:form_height+'px'}">

						<buildForm :bg="'2'" :key="2" :radius_="'2'" v-if="formItems2" :formItems="formItems2"
							:value="form2" @input="formInput2" :select_city_new="[]" :select_city_newd="[]" />
						<view style="width: 100%;height: 30rpx;background-color: #F6F6F6;"></view>
						<buildForm :bg="'2'" :key="3" :radius_="'3'" v-if="formItems3" :formItems="formItems3"
							:value="form3" @input="formInput3" :select_city_new="[]" :select_city_newd="[]" />
						<br>

						<view style="width: 100%;display: flex;margin-top: 50rpx;">
							<view class="my-step custom_" @click="prevStep">{{ $t('上一步') }}</view>
							<view style="padding-bottom: 34.88rpx">
								<u-button :custom-style="{
											width: '356rpx',
											height: '83rpx',
											background: 'linear-gradient(110deg, #DD2910 0%, #F79B29 100%)',
											borderRadius: '56rpx'
										}" hover-class="none" type="primary" @click="subForm">
									{{ $t(jb) }}
								</u-button>
								<view style="width: 100%;height: 100rpx;"></view>
							</view>
						</view>
					</view>
				</block>

				<!-- </scroll-view>
					</swiper-item>
				</swiper>	 -->
			</block>


		</view>

		<vipPopup v-if="vipShow" :show="vipShow" @change="clickVipPopup" />
		<payType v-if="showPayType" :show="showPayType" @close="closePayType" @change="changePayType" :off="off" />
		<authNamePopup v-if="authShow" :show="authShow" @change="clickAuthPopup"></authNamePopup>
	</view>
</template>

<script>
	import buildForm from "@/components/buildForm/index.vue"
	import selectVehicle from "@/components/webview/selectVehicle.vue"
	import vehicleItem from "@/components/webview/vehicleItem.vue"
	import {
		getFormItems,
		formItems
	} from "./formItems"
	import {
		mapForm,
		mapFormItems,
		formRules
	} from '../buildFormItems.js'
	import {
		exitCard,
		getOpenid,
		ImageUrl,
		createC2CConversation,
	} from "@/common/public";
	import {
		IMAGE_URL,
		HTTP_IMG_UTL
	} from "@/config/app";
	import vipPopup from "@/components/vipPopup/index.vue";
	import myTitle from "@/components/myTitle.vue";
	import payType from "@/components/payType.vue";
	import dayjs from 'dayjs'

	import ItemGoods from "@/components/detail/GoodsItem3.vue";
	import ItemAgencyList from '@/components/detail/AgencyListItem.vue'
	import ItemTransportList from "@/components/detail/TransportListItem.vue";
	import ItemFreightForwarder from '@/components/detail/FreightForwarderItem.vue'

	export default {
		components: {
			payType,
			myTitle,
			buildForm,
			vipPopup,
			ItemGoods,
			ItemAgencyList,
			ItemTransportList,
			ItemFreightForwarder,
			selectVehicle, //车辆选择
			vehicleItem, //车辆item
		},
		data() {
			return {
				selectVehicleShow: false,
				selectedVehicleItem: {},
				IMAGE_URL,
				id: 0,
				subDisabled: false,
				details: {
					is_express_price: 1,
					is_warehouse: 1,
					is_load_unload: 1
				},
				//提交的表单详情
				categoryList: [],

				HTTP_IMG_UTL, //远程网址
				baoguan: 0, //报关
				qingguan: 0, //清关

				//发布或下一步 按钮样式
				customStyle: {
					width: '356rpx',
					height: '83rpx',
					marginTop: '40rpx',
					background: 'linear-gradient(110deg, #DD2910 0%, #F79B29 100%)',
					borderRadius: '56rpx'
				},


				step: 1, //竞标步骤
				step_count: 1, //竞标步骤数量

				off: false, //隐现按钮
				type: null, //竞标的类型（商品 运输 跨境货代  佣金发布）
				releaseType: '', //竞标的类型（商品 运输 跨境货代  佣金发布）

				//竞标id
				release_id: 0,
				//竞标详情
				release_detail: [{
					filelist: []
				}],

				//提交 竞标的表单
				form: {},
				form2: {}, //分步骤 提交竞标的表单
				form3: {}, //分步骤 提交竞标的表单


				//应回显 竞标的表单
				formItems: [],
				formItems2: [],
				formItems3: [],

				loading: false, // 加载组件完成
				formLoading: false, // 加载完成后再引入组件
				formDetail: {}, // 回显数组

				vipShow: false, // vip弹窗
				showPayType: false, // 是否显示支付方式框

				plat: '', // 平台
				pay_type: '', // 支付方式

				isAuthName: false, //status !=2 都是未实名认证的
				authShow: false, //未实名认证的  提醒认证框
				form_height: 800,
				form_height1: 800,
				form_height2: 800,
				form_height3: 800,

				itemTouchStartX: '', //按下的位置
				postion: '', //左滑还是右滑

				jb: '参与订单',

			}
		},
		async onLoad(options) {



			this.openid = await getOpenid(this.$u)
			this.release_id = options.release_id
			this.type = options.type

			if (this.release_id === 0 || this.type === null) {
				this.$u.toast('缺少参数：release_id | type')
			}

			this.getReleaseDetail()

			if (this.type === 'goods') {
				this.releaseType = '货物'
			} else if (this.type === 'transport') {
				this.releaseType = '运输'
			} else if (this.type === 'crossborder') {
				this.releaseType = '跨境货代'
			} else if (this.type === 'professional') {
				this.releaseType = '专业代办'
			}

			this.plat = uni.getStorageSync('plat')

			// this.getData({type: options.current}, options.release_id)

			// 为了上架新增的接口，为了隐藏微信支付
			this.$u.api.user.appCheck().then(res => {
				this.off = res.logOff
			})
		},
		onShow() {
			/* 验证是否实名认证 */
			this.$u.api.user.getUserAudit().then(res => {
				this.isAuthName = res.status == 2; //status !=2都是未实名认证的
			})
		},
		onReady() {
			if (uni.getStorageSync('off') == false) {
				uni.setNavigationBarTitle({
					title: this.$t("参与订单")
				})
			} else {
				uni.setNavigationBarTitle({
					title: this.$t("参与竞标")
				})
			}
		},
		mounted() {
			if (uni.getStorageSync('off') == false) {
				this.jb = '参与订单'
			} else {
				this.jb = '参与竞标'
			}
		},
		methods: {
			//选择车辆
			checkItemSubmit(vehicleItem) {
				this.selectedVehicleItem = vehicleItem;
				for (let key in this.form) {
					this.form[key] = vehicleItem[key]
				}
				this.form["vehicle_id"] = vehicleItem.id;

				for (let key in this.form2) {
					if (key === 'images' || key === 'videos' || key === 'files') {
						this.form2[key] = vehicleItem[key].map(item => {
							return {
								src: item
							}
						})
					} else {
						this.form2[key] = vehicleItem[key]
					}
				}

				for (let key in this.form3) {
					this.form3[key] = vehicleItem[key]
				}
				this.form.price_unit = this.release_detail.price_unit
			},
			communicates(i) {
				createC2CConversation(i.user.mobile, this)
			},
			communicate(i) {
				if (this.type == 1) {
					//竞标
					createC2CConversation(i.user.mobile, this)
				} else if (this.type == 2) {
					var mobile = uni.getStorageSync('mobile');

					if (mobile === i.user.mobile) {
						this.$u.toast(this.$t('不能参与自己'));
						return false
					}

					var that = this
					that.$u.api.user.order_join_day_auth({
						lang: that.lang
					}).then(res => {
						if (res == 1) {
							that.$u.route({
								url: '/pages/order/process/buildOrder',
								params: {
									type: "professional",
									release_id: i.id,
								}
							})
						} else {
							if (that.vip) {
								that.vipShow = true
								return
							} else {
								uni.showModal({
									content: that.$t('您的权限不足哦!请联系工作人员!'),
									showCancel: false,
									confirmText: that.$t('是'),
								})
								return false;
							}
						}
					})

				}
			},
			/** 触摸屏幕  */
			itemTouchStart(e) {
				//记录起始位置
				this.itemTouchStartX = e.changedTouches[0].pageX
			},

			/** 触摸结束  */
			itemTouchEnd(e) {
				/** 左滑还是右滑  */
				if (this.itemTouchStartX - e.changedTouches[0].pageX > 30) {
					this.postion = 'right';
					if (this.step < 2) {
						this.step++;
					}
				}
				if (e.changedTouches[0].pageX - this.itemTouchStartX > 30) {
					this.postion = 'left';
					if (this.step > 1) {
						this.step--;
					}
				}
			},

			/** 滑动控制器 */
			swiperController() {
				var that = this
				if (that.postion) {
					uni.pageScrollTo({
						scrollTop: 0, // 将滚动位置设置为顶部
						duration: 0 // 滚动到顶部的动画时长，单位为毫秒
					});
					/** 因为异步原因，必须包一个定时器加入宏任务*/
					setTimeout(() => {
						/** 用户向左滑动，进度会-1， 咱们把进度++，就又回到了当前的item。右边同理 */
						if (that.postion === 'left') {
							that.step++
						} else {
							that.step--
						}
						/** 一定要清空 postion ， 不然死循环了*/
						that.postion = ''
					}, 50)
				}
			},

			/** 左右滑动成功的回调  */
			swiperChange(e) {
				this.swiperController()
			},

			//下一步
			nextStep() {
				var that = this
				var step = this.step
				if (that.step < that.step_count) {
					step++
				}


				if (that.step == 1) {
					console.log(JSON.parse(JSON.stringify(that.formItems)))
					console.log(JSON.parse(JSON.stringify(that.form)))
					if (!formRules(that.formItems, that.form, this)) {
						return false
					}

					that.form_height = that.form_height2
					that.step = step

					uni.pageScrollTo({
						scrollTop: 0, // 将滚动位置设置为顶部
						duration: 0 // 滚动到顶部的动画时长，单位为毫秒
					});
				} else if (that.step == 2) {
					if (!formRules(that.formItems2, that.form2, this)) {
						return false
					}
					that.form_height = that.form_height3
					that.step = step
					uni.pageScrollTo({
						scrollTop: 0, // 将滚动位置设置为顶部
						duration: 0 // 滚动到顶部的动画时长，单位为毫秒
					});
				} else if (that.step == 3) {
					if (!formRules(that.formItems3, that.form3, this)) {
						return false
					}
					that.form_height = that.form_height3
					that.step = step
					uni.pageScrollTo({
						scrollTop: 0, // 将滚动位置设置为顶部
						duration: 0 // 滚动到顶部的动画时长，单位为毫秒
					});
				}



			},
			//上一步
			prevStep() {
				if (this.step > 1) {
					this.step--
				}
				var that = this
				if (that.step == 1) {
					that.form_height = that.form_height1

				} else if (that.step == 2) {
					that.form_height = that.form_height2

				} else if (that.step == 3) {
					that.form_height = that.form_height3

				}
				uni.pageScrollTo({
					scrollTop: 0, // 将滚动位置设置为顶部
					duration: 0 // 滚动到顶部的动画时长，单位为毫秒
				});
				console.log(that.step)
			},
			//跳转当前竞标表单详情
			goDetail() {
				this.$u.route({
					url: "/pages/index/detail/detail",
					params: {
						id: this.release_id,
						type: 2,
						releaseType: this.type
					}
				})
			},
			//获取当前竞标表单详情
			getReleaseDetail() {
				const that = this
				that.$u.api.order.getReleaseDetail({
					release_id: that.release_id,
					type: that.type
				}).then(res => {
					if (res.length === 0) {
						that.$u.toast('竞标信息错误')
						setTimeout(() => {
							that.$u.route({
								url: '/pages/tabbar/index',
								type: 'switchTab'
							})
						}, 2000)
						return false
					}

					that.release_detail = res
					console.log(that.release_detail)

					that.formDetail = {
						is_margin: res.is_margin,
						margin_amount: res.margin_price,
						files: [],
						images: [],
						videos: [],
						price_unit: res["price_unit"],
						number_unit: res["number_unit"],
						number_unit_ru: res["number_unit_ru"],
						car_category_id: {
							value: 0,
							text: '',
							type: 'release_transport'
						},
						release_transport: {
							value: 0,
							text: '',
							type: 'release_transport',
							child: {
								pid: 744,
								value: 0,
								text: '',
								level: 2,
								type: 'release_transport'
							}
						},
						num: res.goods_num,
						product_address: {
							country: '',
							province: 0,
							city: 0
						}
					}

					if (that.release_detail.release_type == 3) {
						if (that.release_detail.human_type == 1) {
							that.formDetail.product_weight = res["goods_weight"]
							that.formDetail.product_volume = res["goods_volume"]
						}
					}


					//货物竞标
					if (that.type == 'goods') {
						that.formItems = getFormItems('goods', res, 1)
						mapFormItems(that.formItems, that.formDetail).then(mapRes => {
							that.formItems = mapRes
						})


						mapForm(that.formItems, that.release_id).then(res => {
							that.form = res
							that.form_height1 = that.formItems.length * 120;
							that.form_height = that.form_height1
							console.log(that.form_height1)
							that.step_count = 1
							that.formLoading = true
						})

						if (that.formItems) {
							that.formItems2 = getFormItems('goods', res, 2)
							that.form_height2 = that.formItems2.length * 110;
							console.log(that.form_height2)
							if (that.formItems2) {
								mapFormItems(that.formItems2, that.formDetail).then(mapRes => {
									that.formItems2 = mapRes
								})
								mapForm(that.formItems2, that.release_id).then(res => {
									that.form2 = res
									that.step_count = 2
								})

								that.formItems3 = getFormItems('goods', res, 3)
								that.form_height3 = that.formItems3.length * 110;

								if (that.formItems3) {
									mapFormItems(that.formItems3, that.formDetail).then(mapRes => {
										that.formItems3 = mapRes
									})
									mapForm(that.formItems3, that.release_id).then(res => {
										that.form3 = res

										that.step_count = 3
									})
								}
							}
						}

						//跨境货代 分几步参与竞标
					} else if (that.type == 'crossborder') {
						that.formItems = getFormItems('crossborder1', res)
						mapFormItems(that.formItems, that.formDetail).then(mapRes => {
							that.formItems = mapRes
						})

						mapForm(that.formItems, that.release_id).then(res => {
							that.form = res
							that.form_height1 = that.formItems.length * 120;
							that.form_height = that.form_height1

							that.step_count = 1
							that.formLoading = true
						})

						if (that.formItems) {
							that.formItems2 = getFormItems('crossborder2', res)
							if (that.formItems2) {
								mapFormItems(that.formItems2, that.formDetail).then(mapRes => {
									that.formItems2 = mapRes
								})
								mapForm(that.formItems2, that.release_id).then(res => {
									that.form2 = res
									that.form_height2 = that.formItems2.length * 220;

									that.step_count = 2
								})

								that.formItems3 = getFormItems('crossborder3', res)
								if (that.formItems3) {
									mapFormItems(that.formItems3, that.formDetail).then(mapRes => {
										that.formItems3 = mapRes
									})
									mapForm(that.formItems3, that.release_id).then(res => {
										that.form3 = res
										that.form_height3 = that.formItems3.length * 200;

										that.step_count = 3
									})
								}
							}
						}

						that.$u.api.collection.getCrossborderListDetail({
							id: that.release_id
						}).then(r => {
							that.details = r
							if (that.details.clearance.indexOf('报关') != '-1') {
								that.baoguan = 1;
							}
							if (that.details.clearance.indexOf('清关') != '-1') {
								that.qingguan = 1;
							}
						})

						//运输 分几步参与竞标					
					} else if (that.type == 'transport') {
						if ((res.release_type == 1) || (res.release_type == 2)) {
							var release_type = res.release_type
							that.formItems = getFormItems('transport', res, 1)
							mapFormItems(that.formItems, that.formDetail).then(mapRes => {
								that.formItems = mapRes
							})


							mapForm(that.formItems, that.release_id).then(res => {
								that.form = res
								if (release_type == 1) {
									that.form_height1 = that.formItems.length * 135;
								} else if (release_type == 2) {
									that.form_height1 = that.formItems.length * 115;
								}
								that.form_height = that.form_height1

								that.step_count = 1
								that.formLoading = true
							})

							if (that.formItems) {
								that.formItems2 = getFormItems('transport', res, 2)
								if (that.formItems2) {
									mapFormItems(that.formItems2, that.formDetail).then(mapRes => {
										that.formItems2 = mapRes
									})
									mapForm(that.formItems2, that.release_id).then(res => {
										that.form2 = res
										if (release_type == 1) {
											that.form_height2 = that.formItems2.length * 110;
										} else if (release_type == 2) {
											that.form_height2 = that.formItems2.length * 230;
										}

										that.step_count = 2
									})

									that.formItems3 = getFormItems('transport', res, 3)
									if (that.formItems3) {
										mapFormItems(that.formItems3, that.formDetail).then(mapRes => {
											that.formItems3 = mapRes
										})
										mapForm(that.formItems3, that.release_id).then(res => {
											that.form3 = res
											that.form_height3 = that.formItems3.length * 230;

											that.step_count = 3
										})
									}
								}
							}

						} else {
							that.formItems = getFormItems('transport', res)
							mapFormItems(that.formItems, that.formDetail).then(mapRes => {
								that.formItems = mapRes
							})
							mapForm(that.formItems, that.release_id).then(res => {
								that.form = res
								that.form_height1 = that.formItems.length * 110;
								that.form_height = that.form_height1

								that.step_count = 1
								that.formLoading = true
							})
						}

					} else {
						that.formItems = getFormItems(that.type, res)
						mapFormItems(that.formItems, that.formDetail).then(mapRes => {
							that.formItems = mapRes
						})
						mapForm(that.formItems, that.release_id).then(res => {
							that.form = res
							that.form_height1 = that.formItems.length * 110;
							that.form_height = that.form_height1

							that.formLoading = true
						})
					}


					if (that.formItems) {
						if (uni.getStorageSync('lang') === 'ru') {
							for (var j = 0; j < that.formItems.length; j++) {
								if (that.formItems[j]['key'] == 'is_margin') {
									that.formItems[j]['show'] = false
								}
								if (that.formItems[j]['key'] == 'margin_amount') {
									that.formItems[j]['show'] = false
								}
							}
							for (var j = 0; j < that.formItems2.length; j++) {
								if (that.formItems2[j]['key'] == 'is_margin') {
									that.formItems2[j]['show'] = false
								}
								if (that.formItems2[j]['key'] == 'margin_amount') {
									that.formItems2[j]['show'] = false
								}
							}
							for (var j = 0; j < that.formItems3.length; j++) {
								if (that.formItems3[j]['key'] == 'is_margin') {
									that.formItems3[j]['show'] = false
								}
								if (that.formItems3[j]['key'] == 'margin_amount') {
									that.formItems3[j]['show'] = false
								}
							}
						}
					}

					that.loading = true

				}).catch(err => {
					console.log(err)
				})
			},
			downLoadFile(url) {
				const that = this
				uni.showLoading({
					title: "download...",
					mask: true
				})
				console.log('下载链接', this.IMAGE_URL + url)
				var downloadTask = uni.downloadFile({
					url: that.IMAGE_URL + url,
					success(res) {
						uni.hideLoading()
						console.log('tempFilePath', res.tempFilePath)
						const tempFilePath = res.tempFilePath
						uni.openDocument({
							filePath: tempFilePath,
							showMenu: true,
							success: function(file) {
								console.log('file-success', file);
							}
						});
					},
				})
				downloadTask.onProgressUpdate(({
					progress,
					totalBytesWritten,
					totalBytesExpectedToWrite
				}) => {
					if (progress === 100) {
						downloadTask.offProgressUpdate();
					}
				})
			},


			//提交竞标表单
			subForm() {
				const that = this
				console.log(that.form3.is_margin)
				var mergedObject = Object.assign({}, that.form, that.form2, that.form3);

				if (!this.isAuthName) {
					this.authShow = true;
					return;
				}

				mergedObject.release_id = this.release_id
				mergedObject.type = this.type
				mergedObject.openid = this.openid
				mergedObject.speed_unit = this.release_detail.speed_unit

				// mergedObject.price_unit = this.release_detail.price_unit
				// 判断是否要交保证金

				if (mergedObject.is_margin === '2') {
					if (mergedObject.margin_amount == '' || mergedObject.margin_amount == 0 || mergedObject
						.margin_amount == 0.00) {
						that.$u.toast(that.$t('请输入有效保证金金额，缴纳成功后即可参与成功'));
						return false;
					}
					// that.$u.toast(that.$t('该竞标需要缴纳保证金，缴纳成功后即可参与成功'))
				}
				if (mergedObject.is_margin === '1') {
					if (mergedObject.margin_amount > 0) {
						mergedObject.margin_amount = 0;
						//that.$u.toast(that.$t('不缴纳保证金，金额输入为0'));return false;
					}
				} else {
					if ((mergedObject.is_margin) && (mergedObject.is_margin != 'undefined') && (mergedObject.is_margin !=
							undefined)) {
						if ((mergedObject.margin_amount) && (mergedObject.margin_amount != 'undefined') && (mergedObject
								.margin_amount != undefined)) {
							const regex = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/; // 正则表达式，匹配最多有两位小数的金额数字
							if (!regex.test(mergedObject.margin_amount)) {
								that.$u.toast(that.$t('请输入正确的金额格式!'));
								return false;
							}
						}
					}
				}

				if (mergedObject.parameter) {
					mergedObject.parameter = JSON.stringify(mergedObject.parameter)
				}


				if (!formRules(that.formItems, mergedObject, this)) {
					return false
				}

				if (that.formItems2) {
					if (!formRules(that.formItems2, mergedObject, this)) {
						return false
					}
				}

				if (that.formItems3) {
					if (!formRules(that.formItems3, mergedObject, this)) {
						return false
					}
				}

				console.log("off====", that.off)
				if (that.off == false) {
					mergedObject.is_margin = '1';
				}
				// console.log(mergedObject.is_margin);return false;		
				// 支付环境判断
				if (mergedObject.is_margin === '2') {
					const lang = uni.getStorageSync('lang')
					if (!this.release_detail.margin_price || this.release_detail.margin_price * 1 === 0) {
						console.log('this.release_detail.margin_price', this.release_detail.margin_price)
						mergedObject.is_margin = '1'
					} else {
						if (lang === 'zh') {
							if (that.plat === 'web') {
								that.$u.toast(this.$t('请在小程序或App中支付'))
								return
							}
							if (that.pay_type === '') {
								this.showPayType = true
								return
							}
						} else {
							mergedObject.is_margin = '1'
						}
					}
				}

				mergedObject.id = ''
				mergedObject.pay_type = that.pay_type
				mergedObject.method = that.plat


				if ((that.off == false) && (that.plat == 'app')) {
					mergedObject.pay_type = 'alipay';
				}

				uni.showLoading({
					title: "Loading...",
					mask: true
				})
				that.$u.api.order.saveJoinOrder(mergedObject).then(res => {
					uni.hideLoading();
					if (mergedObject.is_margin === '2') {
						if (that.plat === 'mp-weixin') {
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: res.timeStamp,
								nonceStr: res.nonceStr,
								package: res.package,
								signType: res.signType,
								paySign: res.paySign,
								success: function(res) {
									console.log('success:' + JSON.stringify(res));
									that.$u.toast(that.$t('操作成功'))
									setTimeout(() => {
										that.$u.route({
											url: '/pages/tabbar/order/index',
											type: 'switchTab'
										})
									}, 2000)
								},
								fail: function(err) {
									console.log('fail:' + JSON.stringify(err));
									that.$u.toast(that.$t("取消支付"))
								}
							});
						} else if (that.plat === 'app') {
							uni.requestPayment({
								provider: that.pay_type,
								orderInfo: res, // 微信-支付宝订单数据
								success: (res) => {
									console.log('success-score-order:' + JSON.stringify(res));
									that.$u.toast(that.$t('操作成功'))
									setTimeout(() => {
										that.$u.route({
											url: '/pages/tabbar/order/index',
											type: 'switchTab'
										})
									}, 2000)
								},
								fail: (err) => {
									console.log('fail:' + JSON.stringify(err));
									that.$u.toast(that.$t("取消支付"))
								},
							});
						}
					} else {
						that.$u.toast(that.$t("参与成功"))
						setTimeout(() => {
							that.$u.route({
								url: '/pages/tabbar/user/index',
								type: 'switchTab'
							})
						}, 2000)
					}
				}).catch(err => {
					console.log(err)
				})
			},

			formInput(val) {
				this.form = val
				if (val.send_time && val.speed) {
					this.form.reach_time = dayjs(val.send_time).add(Number(val.speed), 'day').format('YYYY-MM-DD')
				} else {
					this.form.reach_time = null;
				}
			},
			formInput2(val) {
				this.form2 = val
			},
			formInput3(val) {
				this.form3 = val
			},



			clickAuthPopup(e) {
				this.authShow = false
			},
			clickVipPopup() {
				this.vipShow = false
			},
			closePayType() {
				this.showPayType = false
			},
			changePayType(e) {
				this.pay_type = e
				this.subForm()
			},
			getShowMsg() {
				if (this.releaseType === '运输') {
					let str = ''
					if (this.release_detail.release_type === '1') {
						str = this.$t('有车求货')
					} else if (this.release_detail.release_type === '2') {
						str = this.$t('有货求车')
					} else {
						str = this.$t('人力捎货')
						if (this.release_detail.human_type === '1') {
							str += '-' + this.$t('货源信息')
						} else {
							str += '-' + this.$t('我要带货')
						}
					}
					return this.$t(this.releaseType) + '-' + str
				} else {
					return this.$t(this.releaseType)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.sel {
		color: $u-type-success;
	}

	.goods_now {
		padding: 0 10px;
		height: 80rpx;
		line-height: 80rpx;
		border-bottom: 1px #f6f6f6 solid;
		display: flex;
		background: #fefcf6;
		font-size: 12px;
	}

	.detailData_content {
		word-break: break-all;
		padding: 5rpx;
		color: #008aff;
		border-radius: 20rpx;
		background-color: rgb(235, 241, 245);
		margin-left: 2%;
		width: 96%;
	}

	.page {
		background-color: $my-bgColorF6F6F6;
		padding: 30rpx 40rpx 20rpx 40rpx;

		.my-content-bottom {
			border-radius: 14rpx;
		}

		.my-detail {
			background-color: $my-bgColorFFFFFF;
			display: flex;
			padding: 10rpx 40rpx 40rpx 40rpx;
			justify-content: space-between;
		}
	}

	.order_body_details {
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		padding: 19.19rpx;
		padding-top: 0rpx;
		// margin-top: 63rpx;
	}

	.button {
		max-width: 220rpx;
		background: linear-gradient(132deg, #FBAA52 0%, #E96444 100%);
		border-radius: 14rpx;
		font-size: 29rpx;
		font-weight: 600;
		color: #FFFFFF;
		line-height: 35rpx;
		margin-right: 15rpx;
		text-align: center;
		padding: 15rpx;
	}

	.custom_ {
		width: 256rpx;
		height: 83rpx;
		color: #F79B29;
		text-align: center;
		background-color: #ffffff;
		border-radius: 56rpx;
		border: 1px solid #F79B29;
		line-height: 83rpx;
		margin-left: 5%;
		margin-right: 5%;
	}

	.title {
		border-left: 8rpx solid #ff9a22;
		margin-left: 16rpx;
		padding-left: 16rpx;
		margin-bottom: 16rpx;
	}

	.server {
		background-color: #fefcf6;

		.flex {
			display: flex;
			justify-content: space-evenly;
			margin-bottom: 40rpx;
			text-align: center;
			width: 100%;
			padding: 40rpx;
			padding-top: 0rpx;
			padding-bottom: 20rpx;

			img {
				width: 150rpx;
				height: 130rpx;
			}

			.headline_img {
				height: 150rpx;
			}
		}
	}
</style>